package com.xipu.yygh.listener;

import com.rabbitmq.client.Channel;
import com.xipu.yygh.rabbit.constant.MqConst;
import com.xipu.yygh.service.SmsService;
import com.xipu.yygh.vo.msm.MsmVo;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * description: 监听器
 * @author: gql
 * @date: 2022/05
 */
@Component
public class SmsListener {
    /**
     * 发送短信服务
     */
    @Autowired
    private SmsService smsService;

    /**
     * 收到消息后发短信
     * @param msmVo 短信实体VO
     * @param message 消息对象
     * @param channel 信道
     */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = MqConst.QUEUE_MSM_ITEM, durable = "true"),
            exchange = @Exchange(value = MqConst.EXCHANGE_DIRECT_MSM),
            key = {MqConst.ROUTING_MSM_ITEM}))
    public void send(MsmVo msmVo, Message message, Channel channel) {
        try {
            boolean send = smsService.sendMessage(msmVo);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
